package com.vains.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vains.dto.AuthorityDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Set;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author vains
 * @since 2020-06-08
 */
@Data
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
@ApiModel(value="OauthUser对象", description="用户表")
public class OauthUser implements Serializable, UserDetails {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @TableId(value = "user_id", type = IdType.AUTO)
    private Integer userId;

    @ApiModelProperty(value = "用户名称")
    private String userName;

    @ApiModelProperty(value = "手机号")
    private String userPhone;

    @ApiModelProperty(value = "地址")
    private String userAddress;

    @ApiModelProperty(value = "是否启用")
    private Boolean userEnabled;

    @ApiModelProperty(value = "账号")
    private String userNumber;

    @ApiModelProperty(value = "密码")
    private String userPassword;

    @ApiModelProperty(value = "描述")
    private String userRemark;

    @ApiModelProperty(value = "微信登陆获取的信息")
    private String userOpenid;

    @ApiModelProperty(value = "值为1时是男性，值为2时是女性，值为0时是未知")
    private Integer userSex;

    @ApiModelProperty(value = "值为1时是男性，值为2时是女性，值为0时是未知")
    private Date userBirthDay;

    @ApiModelProperty(value = "省份")
    private String userProvince;

    @ApiModelProperty(value = "城市")
    private String userCity;

    @ApiModelProperty(value = "头像")
    private String userHeadimgurl;

    @ApiModelProperty(value = "用户创建时间")
    private Date userCreateTime;

    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有的权限列表")
    private Set<AuthorityDto> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return this.userPassword;
    }

    @Override
    public String getUsername() {
        return this.userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.userEnabled;
    }
}
